import * as React from "react";
import Modal from "antd/es/modal/Modal";
import {Button, Card, Col, Form, Input, InputNumber, notification, Row} from "antd";
import {PlusOutlined, UserOutlined} from "@ant-design/icons";
import {createKey, disableKey, disableOwnKey, updateKey, updateOwnKey} from "../../requests/KeyManageRequest";


class DisableVerifyKeyModal extends React.Component{

    constructor(props) {
        super(props);
        this.state = {
            isModalVisible: false,
            formRef: React.createRef(),
            isOwn:this.props.isOwn
        };
        this.props.onRef(this)
    }

    showModal = () => {
        this.setState({
            isModalVisible: true
        })
    };

    handleCancel = () => {
        this.setState({
            isModalVisible: false
        })
    };

    handleOk = () => {

        if (!this.props.keyName){
            notification.error({message: "禁用激活码失败", description: "请在表格中选择激活码之后进行禁用！"});
            return
        }

        if (this.state.isOwn===true){
            console.log("Begin to disable own verify key with params:" + JSON.stringify(this.props.keyName))
            disableOwnKey(this.props.keyName).then(edpKey => {
                notification.info({message: "禁用激活码成功", description: "禁用激活码" + edpKey.result.keyName + "成功"});
            })
        }else {
            console.log("Begin to disable all key with params:" + JSON.stringify(this.props.keyName))
            disableKey(this.props.keyName).then(edpKey => {
                notification.info({message: "禁用激活码成功", description: "禁用激活码" + edpKey.result.keyName + "成功"});
            })
        }

        this.setState({
            isModalVisible: false
        })

    };

    render = () => {
        return (
            <Modal title="禁用激活码" visible={this.state.isModalVisible} onOk={this.handleOk} onCancel={this.handleCancel}>
                <p>确认禁用激活码{this.props.keyName}</p>
            </Modal>
        );
    }
}

export default DisableVerifyKeyModal